package cn.yunhe.dao.impl;

import cn.yunhe.dao.IUserDao;
import cn.yunhe.entity.User;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("userDao")
public class UserDaoImpl extends HibernateDaoSupport implements IUserDao {

    @Override
    public void addUser(User user) {
        getHibernateTemplate().save(user);
    }

    @Override
    public User loginUser(User user) {
        Object[] params = {user.getName(), user.getPwd()};
        List<User> list = getHibernateTemplate().find("from User where name = ?  and pwd  = ?", params);
        return list.size() > 0 ? list.get(0) : null;
    }

}
